﻿using Domain.NetworkRemoteDevice;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Threading;
using Domain.NetworkService;
using Domain.NetworkService.Behaviors.Interfaces;

namespace Domain.NetworkRemoteDevice
{
    public class RemoteDevice
    {
        public List<NetworkServiceTest> Tests { get; private set; }
        public string Name { get; private set; }
        public RemoteDevice(string name)
        {
            Name = name;
            Tests = new List<NetworkServiceTest>();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="test"></param>
        /// <param name="timeout"></param>
        /// <returns>true - если тест добавлен, false - если тест уже сущесвует</returns>
        public bool AddTest(INetworkServiceTest test)
        {
            NetworkServiceTestID id = new NetworkServiceTestID(Name, test.Description);
            if ((!Tests.Exists(item => item.ID.Equals(id))))
            {
                Tests.Add(new NetworkServiceTest(id, test));
                return true;
            }
            return false;
        }
        public bool RemoveTest(IDescription description)
        {
            NetworkServiceTestID id = new NetworkServiceTestID(Name, description);
            if ((Tests.Exists(item => item.ID.Equals(id))))
            {
                Tests.FindAll(item => item.ID.Equals(id)).First().Stop();
                Tests.RemoveAll(item => item.ID.Equals(id));
                return true;
            }
            return false;
        }
    }
}
